﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace jSLCore.Client.Presentation.Controls
{
    public class ImageGroupBoxBase : ContentControl
    {
        #region ImageSource DependencyProperty
        public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register("ImageSource",
                                                                                                    typeof(ImageSource
                                                                                                        ),
                                                                                                    typeof(ImageGroupBoxBase), null);


        public ImageSource ImageSource
        {
            get { return (ImageSource)GetValue(ImageSourceProperty); }
            set
            {
                SetValue(ImageSourceProperty, value);
            }
        }

        public Image imContent
        {
            get { return (Image)GetTemplateChild("PART_image"); }
        }

        #endregion

        #region Header DependencyProperty
        public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register("Header", typeof(object),
                                                                                               typeof(ImageGroupBoxBase), null);

        public object Header
        {
            get { return GetValue(HeaderProperty); }
            set { SetValue(HeaderProperty, value); }
        }

        protected ContentPresenter headerContent
        {
            get { return (ContentPresenter)GetTemplateChild("PART_header");}
        }

        #endregion

        #region ScrollBars
        public static readonly DependencyProperty ScrollBarVisibleProperty =
           DependencyProperty.Register("ScrollBarVisible", typeof(ScrollBarVisibility), typeof(ImageGroupBoxBase),
                                       new PropertyMetadata(ScrollBarVisibility.Disabled));

        public ScrollBarVisibility ScrollBarVisible
        {
            get { return (ScrollBarVisibility)GetValue(ScrollBarVisibleProperty); }
            set { SetValue(ScrollBarVisibleProperty, value); }
        } 

        public bool AllowScroll
        {
            get { return ScrollBarVisible == ScrollBarVisibility.Auto; }
            set
            {
                ScrollBarVisible = value?ScrollBarVisibility.Auto : ScrollBarVisibility.Disabled;
            }
        }
        #endregion

      /*  #region HeaderHeight

        public static readonly DependencyProperty HeaderHeightProperty = DependencyProperty.Register("HeaderHeight",
                                                                                                     typeof(GridLength),
                                                                                                     typeof(
                                                                                                         ImageGroupBoxBase), new PropertyMetadata(GridLength.Auto,HeaderHeight_Changed));

        private static void HeaderHeight_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
           /* object newValue = e.NewValue;
            var imageGroupBoxBase = d as ImageGroupBoxBase;
            imageGroupBoxBase.UpdateLayout();
            imageGroupBoxBase.InvalidateArrange();
            imageGroupBoxBase.InvalidateMeasure();♥1♥
        }

        public GridLength HeaderHeight
        {
            get { return (GridLength)GetValue(HeaderHeightProperty); }
            set { SetValue(HeaderHeightProperty, value); }
        }
        #endregion */

        #region CornerRadius
        public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register("CornerRadius",
                                                                                                     typeof(CornerRadius),
                                                                                                     typeof (
                                                                                                         ImageGroupBoxBase
                                                                                                         ),null);
        public CornerRadius CornerRadius
        {
            get { return (CornerRadius)GetValue(CornerRadiusProperty); }
            set {SetValue(CornerRadiusProperty,value);}
        }
        #endregion
    }
}